package com.terren.spider.core.html.util;

import java.util.Properties;

import com.terren.spider.core.html.configuration.strategy.BuildCookieBlackListStrategy;
import com.terren.spider.core.html.configuration.strategy.BuildCookieWhiteListStrategy;
import com.terren.spider.entity.config.SysConfig;
import com.terren.spider.util.common.CommonUtil;

public class BuildCookieStrategyUtil {
	private static BuildCookieWhiteListStrategy buildCookieWhiteList;
	private static BuildCookieBlackListStrategy buildCookieBlackList;
	
	
	/**
	 * cookie白名单策略
	 * @return
	 */
	public static BuildCookieWhiteListStrategy getBuildCookieWhiteList() {
		if (null==buildCookieWhiteList) {
	        Properties properties = CommonUtil.getSysConfigProperties();
	        buildCookieWhiteList = new BuildCookieWhiteListStrategy();
            String whiteListProperty = properties.getProperty(SysConfig.COOKIE_WHITE_LIST_STRATEGY);
            if (null!=whiteListProperty) {
            	buildCookieWhiteList.addAllHost(whiteListProperty);
			}
		}
		return buildCookieWhiteList;
	}
	
	/**
	 * cookie黑名单策略
	 * @return
	 */
	public static BuildCookieBlackListStrategy getBuildCookieBlackList() {
		if (null==buildCookieBlackList) {
	        Properties properties = CommonUtil.getSysConfigProperties();
	        buildCookieBlackList = new BuildCookieBlackListStrategy();
            String blackListProperty = properties.getProperty(SysConfig.COOKIE_BLACK_LIST_STRATEGY);
            if (null!=blackListProperty) {
            	buildCookieBlackList.addAllHost(blackListProperty);
			}
		}
		return buildCookieBlackList;
	}
	
}
